using System;
using System.Collections.Generic;
using System.Text;

namespace CodePlex.Resourceful.Bookmarks.Model
{
    public class BookmarkEngine
    {


        private readonly List<UserAccount> _users = new List<UserAccount>();
        private readonly List<Bookmark> _bookmarks = new List<Bookmark>();


        public UserAccount FindUser(string name)
        {
            return _users.Find(delegate(UserAccount item)
            {
                return item.Name == name;
            });
        }

        public void Remove(UserAccount user)
        {
            _users.Remove(user);
        }

        public void Add(UserAccount user)
        {
            _users.Add(user);
        }

        public Bookmark FindBookmark(string username, string uriHash)
        {
            return _bookmarks.Find(delegate(Bookmark item)
            {
                return item.UserID == username && item.URIHash == uriHash;
            });
        }

        public void Add(Bookmark bookmark)
        {
            bookmark.Timestamp = Utils.TruncateToSeconds(DateTime.Now);
            _bookmarks.Add(bookmark);
        }

        public void Remove(Bookmark bookmark)
        {
            _bookmarks.Remove(bookmark);
        }



       
        public IEnumerable<Bookmark> FindBookmarks(UserAccount user)
        {
            return _bookmarks.FindAll(delegate(Bookmark item)
            {
                return item.UserID == user.Name;
            });
        }
    }
}
